package com.study.scheduled.config;

import com.study.scheduled.thread.PublicThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

@Configuration
@EnableScheduling
public class DynamicScheduleConfig implements SchedulingConfigurer {

    @Autowired
    private OpcParams opcParams;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        // 创建定时任务线程
        taskRegistrar.addFixedDelayTask(new PublicThread(opcParams.getThreadNum(), opcParams.getInterfaces()), opcParams.getReadTime());
    }
}
